var QualityAssurances = {//质量管理管理初始化
    id: "QualityAssurancesOneTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

function _cellStyles(value, row, index) {
    if (row.status == 1) {
        return {css: {"background-color": "#fff1d5", "overflow": "hidden", "white-space": "nowrap", "text-overflow": "ellipsis"}}
    } else {
        return {css: {"overflow": "hidden", "white-space": "nowrap", "text-overflow": "ellipsis"}}
    }
}

QualityAssurances.initColumn = function () {//初始化表格的列
    return [
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: 'reservationsId', field: 'reservationsId', visible: false, align: 'center', valign: 'middle'},
        {title: 'num', field: 'num', visible: false, align: 'center', valign: 'middle'},
        {title: 'status', field: 'status', visible: false, align: 'center', valign: 'middle'},
        {
            title: '患者姓名', field: 'customerName', align: 'center', valign: 'middle', sortable: true, width: 70,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '病历号', field: 'medicalRecordNumber', align: 'center', valign: 'middle', sortable: true, width: 70,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '上传时间', field: 'createTime', align: 'center', valign: 'middle', sortable: true, width: 120,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '暂存类型', field: 'status', align: 'center', valign: 'middle', sortable: true, width: 70,
            formatter: function (value, row, index) {
                if (row.status == 0) {
                    return '术前暂存'
                } else {
                    return '术后暂存'
                }
            },
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '上传人姓名', field: 'createName', align: 'center', valign: 'middle', sortable: true, width: 70,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '门诊', field: 'arrivalStore', align: 'center', valign: 'middle', sortable: true, width: 70,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '医生', field: 'doctor', align: 'center', valign: 'middle', sortable: true, width: 70,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '护士', field: 'nurse', align: 'center', valign: 'middle', sortable: true, width: 70,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '操作', field: 'operation', align: 'center', valign: 'middle', width: 60,
            formatter: function (value, row, index) {
                var ids = row.num + "," + row.reservationsId + "," + 1 + "," + 'doctor';
                return '<button title="初诊详情修改" onclick="QualityAssurances.displayUpdateIconTypes1(' + "'" + ids + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-pencil"></span></button> ' +
                 '<button title="完成详情修改" onclick="QualityAssurances.orthodonticComplexDisplay(' + "'" + ids + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-pencil"></span></button>';
            },
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '操作', field: 'operation2', align: 'center', valign: 'middle', width: 60, visible: false,
            formatter: function (value, row, index) {
                    var ids = row.num + "," + row.reservationsId + "," + 2;
                return '<button title="详情" onclick="QualityAssurances.canalScoreIconTypes(' + "'" + ids + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-pencil"></span></button> ' +
                    '<button title="删除" onclick="QualityAssurances.deleteCanalScoreIconTypes(' + "'" + ids + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-trash"></span></button>';
            },
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '操作', field: 'operation3', align: 'center', valign: 'middle', width: 60, visible: false,
            formatter: function (value, row, index) {
                var ids = row.num + "," + row.reservationsId + "," + 2;
                return '<button title="术前详情" onclick="QualityAssurances.scalingUpdateIconTypes(' + "'" + ids + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-pencil"></span></button> ' +
                    '<button title="上传术后" onclick="QualityAssurances.openUpdateIconTypes(' + "'" + ids + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-plus"></span></button> ' +
                    '<button title="术前删除" onclick="QualityAssurances.deleteScalingUpdateIconTypes(' + "'" + ids + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-trash"></span></button>';
            },
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '操作', field: 'operation4', align: 'center', valign: 'middle', width: 60, visible: false,
            formatter: function (value, row, index) {
                var ids = row.num + "," + row.reservationsId + "," + 2;
                return '<button title="术前详情" onclick="QualityAssurances.periodontalUpdateIconTypes(' + "'" + ids + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-pencil"></span></button> ' +
                    '<button title="术前上传" onclick="QualityAssurances.openUpdatePeriodontal(' + "'" + ids + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-plus"></span></button> ' +
                    '<button title="术前删除" onclick="QualityAssurances.deletePeriodontalIconTypes(' + "'" + ids + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-trash"></span></button>';
            },
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '操作', field: 'operation5', align: 'center', valign: 'middle', width: 60, visible: false,
            formatter: function (value, row, index) {
                var ids = row.num + "," + row.reservationsId + "," + 2;
                return '<button title="术前详情" onclick="QualityAssurances.plantScoreUpdateIconTypes(' + "'" + ids + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-pencil"></span></button> ' +
                    '<button title="术后上传" onclick="QualityAssurances.plantScoreIconTypes(' + "'" + ids + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-plus"></span></button> ' +
                    '<button title="术前删除" onclick="QualityAssurances.deletePlantIconTypes(' + "'" + ids + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-trash"></span></button>';
            },
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '操作', field: 'operation6', align: 'center', valign: 'middle', width: 60, visible: false,
            formatter: function (value, row, index) {
                var ids = row.num + "," + row.reservationsId + "," + 2;
                return '<button title="术前详情" onclick="QualityAssurances.repairScoreUpdateIconTypes(' + "'" + ids + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-pencil"></span></button> ' +
                    '<button title="术后上传" onclick="QualityAssurances.openRepairScoreIconTypes(' + "'" + ids + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-plus"></span></button> ' +
                    '<button title="术前删除" onclick="QualityAssurances.deleteRepairIconTypes(' + "'" + ids + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-trash"></span></button>';
            },
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        }
    ];
};
//正畸初诊图片回显
QualityAssurances.displayUpdateIconTypes1 = function (ids) {
    var index = layer.open({
        type: 2,
        title: '正畸初诊图片回显',
        area: ['85%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/orthodonticsDisplay1/' + ids
    });
    this.layerIndex = index;
};

//正畸完成图片回显
QualityAssurances.orthodonticComplexDisplay = function (ids) {
    var index = layer.open({
        type: 2,
        title: '正畸完成图片回显',
        area: ['85%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/orthodonticComplexDisplay/' + ids
    });
    this.layerIndex = index;
};

//根管图片回显
QualityAssurances.canalScoreIconTypes = function(ids) {
    var index = layer.open({
        type: 2,
        title: '根管图片回显',
        area: ['85%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/rootCanalScoreDisplay/' + ids
    });
    this.layerIndex = index;
};
//根管图片 - 删除
QualityAssurances.deleteCanalScoreIconTypes = function(ids) {
    if (confirm("是否删除此组数据")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/deleteRootCanal",
            type: "post",
            data: {"ids": ids},
            success: function (data) {
                RootCanalScoreTable.search();
                Feng.success("删除成功！");
            },
            error: function (data) {
                alert("删除失败！");
            }
        });
    }
};
//洁牙术前图片回显 - 暂存
QualityAssurances.scalingUpdateIconTypes = function(ids) {
    var index = layer.open({
        type: 2,
        title: '洁牙术前图片回显',
        area: ['85%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/uploadScalingDisplay/' + ids
    });
    this.layerIndex = index;
};
//上传洁牙术后
QualityAssurances.openUpdateIconTypes = function (ids){
    var index = layer.open({
        type: 2,
        title: '上传洁牙术后',
        area: ['85%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/uploadScalingComplex/' + ids
    });
    this.layerIndex = index;
};
//上传洁牙图片 - 删除
QualityAssurances.deleteScalingUpdateIconTypes = function(ids) {
    if (confirm("是否删除此组数据")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/deleteSubScaling",
            type: "post",
            data: {"ids": ids},
            success: function (data) {
                uploadScalingTable.search();
                Feng.success("删除成功！");
            },
            error: function (data) {
                alert("删除失败！");
            }
        });
    }
};
//牙周术前图片回显 - 暂存
QualityAssurances.periodontalUpdateIconTypes = function(ids) {
    var index = layer.open({
        type: 2,
        title: '牙周术前图片回显',
        area: ['85%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/uploadPeriodontalDisplay/' + ids
    });
    this.layerIndex = index;
};
//上传牙周术后
QualityAssurances.openUpdatePeriodontal = function (ids){
    var index = layer.open({
        type: 2,
        title: '上传牙周术后',
        area: ['85%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/uploadPeriodontalComplex/' + ids
    });
    this.layerIndex = index;
}
//上传牙周图片 - 删除
QualityAssurances.deletePeriodontalIconTypes = function(ids) {
    if (confirm("是否删除此组数据")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/deleteStoragePeriodontal",
            type: "post",
            data: {"ids": ids},
            success: function (data) {
                uploadPeriodontalTable.search();
                Feng.success("删除成功！");
            },
            error: function (data) {
                alert("删除失败！");
            }
        });
    }
};
//种植图片回显 - 暂存
QualityAssurances.plantScoreUpdateIconTypes = function(ids) {
    var index = layer.open({
        type: 2,
        title: '种植图片回显',
        area: ['85%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/uploadPlantScoreDisplay/' + ids
    });
    this.layerIndex = index;
};
//上传种植戴牙
QualityAssurances.plantScoreIconTypes = function(ids) {
    var index = layer.open({
        type: 2,
        title: '上传种植戴牙',
        area: ['85%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/uploadPlantScoreComplex/' + ids
    });
    this.layerIndex = index;
};

//上传种植图片 - 删除
QualityAssurances.deletePlantIconTypes = function(ids) {
    if (confirm("是否删除此组数据")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/deleteSubPlant",
            type: "post",
            data: {"ids": ids},
            success: function (data) {
                DentalPeripheryScoreTable.search();
                Feng.success("删除成功！");
            },
            error: function (data) {
                alert("删除失败！");
            }
        });
    }
};
//修复图片回显 - 暂存
QualityAssurances.repairScoreUpdateIconTypes = function(ids) {
    var index = layer.open({
        type: 2,
        title: '修复图片回显',
        area: ['85%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/uploadRepairScoreDisplay/' + ids
    });
    this.layerIndex = index;
};
//上传修复戴牙
QualityAssurances.openRepairScoreIconTypes = function(ids) {
    var index = layer.open({
        type: 2,
        title: '上传修复',
        area: ['80%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/uploadRepairScoreComplex/' + ids
    });
    this.layerIndex = index;
};
//上传修复图片 - 删除
QualityAssurances.deleteRepairIconTypes = function(ids) {
    if (confirm("是否删除此组数据")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/deleteSubRepair",
            type: "post",
            data: {"ids": ids},
            success: function (data) {
                uploadRepairScoreTable.search();
                Feng.success("删除成功！");
            },
            error: function (data) {
                alert("删除失败！");
            }
        });
    }
};

QualityAssurances.check = function () { // 检查是否选中
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        QualityAssurances.seItem = selected[0];
        return true;
    }
};

QualityAssurances.search = function () {//图片质量管理查询
    QualityAssurances.table.refresh({query: QualityAssurances.formParams()});
};

QualityAssurances.search1 = function () {
    if($("#cacheImage").val() == 1){
        $('#QualityAssurancesOneTable').bootstrapTable('showColumn', 'operation');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation2');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation3');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation4');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation5');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation6');
    }
    if($("#cacheImage").val() == 2){
        $('#QualityAssurancesOneTable').bootstrapTable('showColumn', 'operation2');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation3');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation4');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation5');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation6');
    }
    if($("#cacheImage").val() == 3){
        $('#QualityAssurancesOneTable').bootstrapTable('showColumn', 'operation3');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation2');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation4');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation5');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation6');
    }
    if($("#cacheImage").val() == 4){
        $('#QualityAssurancesOneTable').bootstrapTable('showColumn', 'operation4');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation2');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation3');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation5');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation6');
    }
    if($("#cacheImage").val() == 5){
        $('#QualityAssurancesOneTable').bootstrapTable('showColumn', 'operation5');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation2');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation3');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation4');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation6');
    }
    if($("#cacheImage").val() == 6){
        $('#QualityAssurancesOneTable').bootstrapTable('showColumn', 'operation6');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation2');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation3');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation4');
        $('#QualityAssurancesOneTable').bootstrapTable('hideColumn', 'operation5');
    }
    $("#cacheImageValues").val($("#cacheImage").val());
    QualityAssurances.search();
}

QualityAssurances.getData = function () { // 片区筛选
    var area = $("#area").val();
    $.ajax({
        url: Feng.ctxPath + "/dept/getListByArea",
        type: "post",
        data: {"area": area},
        success: function (data) {
            $('#arrivalStore').empty();
            $('#arrivalStore').append('<option value="">请选择</option>');
            for (var i = 0; i < data.length; i++) {
                $('#arrivalStore').append("<option value=" + data[i].simplename + ">" + data[i].simplename + "</option>");
            }
            QualityAssurances.search();
        },
        error: function (data) {
            alert("系统错误！");
        }
    });
};

QualityAssurances.formParams = function () {//查询质量管理列表
    var queryData = {};
    queryData['startCreateTime'] = $("#startUploadTime").val();
    queryData['endCreateTime'] = $("#endUploadTime").val();
    queryData['createName'] = $("#addName").val();
    queryData['arrivalStore'] = $("#arrivalStore").val();
    queryData['status'] = $("#status").val();
    queryData['cacheImage'] = $("#cacheImageValues").val();
    queryData['area'] = $("#area").val();
    return queryData;
};

QualityAssurances.resetSearch = function () {//重置
    $("#startUploadTime").val("");
    $("#endUploadTime").val("");
    $("#addName").val("");
    $("#arrivalStore").val("");
    $("#status").val("");
    $("#scoreTOTAL").val("");
    QualityAssurances.search();
};

QualityAssurances.time = function () {//初始化赋值时间 + 请求数据
    var outpatientName = $('#outpatientName').val();
    var areaAbbreviation = $('#areaAbbreviation').val();
    $("#area option[value='" + areaAbbreviation + "']").attr("selected", "selected");
    $("#arrivalStore option[value='" + outpatientName + "']").attr("selected", "selected");
    $("#startUploadTime").val(setDateTime(new Date(), 0) + " " + "00:00:00");
    $("#endUploadTime").val(setDateTime(new Date(), 0) + " " + "23:59:59");
    QualityAssurances.search();
};

checkDate = function () {QualityAssurances.search();};

$(function () {
    var defaultColunms = QualityAssurances.initColumn();
    var table = new BSTable(QualityAssurances.id, "/cacheImage/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(QualityAssurances.formParams());
    QualityAssurances.table = table.init();
    QualityAssurances.time();
});